<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="servlets.message.*"%>
<%@ page import="org.hibernate.SessionFactory"%>
<%@ page import="org.hibernate.Session"%>
<%@ page import="java.util.List"%>
<%@ page import="hibernate.model.*"%>
<%@ page import="hibernate.util.HibernateUtil"%>
<%@ page import="hibernate.method.*"%>
<%@ page import="hibernate.method.UserMethods"%>
<div class="page-header">
	<h2 class="page-title">zarzadzanie kategoriami</h2>
</div>

<br />

<div id="content">
<%
						//String type = "client";
						SessionFactory sessionFactory = HibernateUtil
								.getSessionAnnotationFactory();
						Session s = sessionFactory.openSession();
						s.beginTransaction();
						CategoryMethods catm = new CategoryMethods();
						GameCategoryMethods gcatm= new GameCategoryMethods();
						List <Category> catlist = catm.listAllCategories(sessionFactory, s);
						
					%> 
					
					<div class="page-header">
<h2 class="page-title">Utworzone</h2>
</div>

		
		
		<%
		if (catlist.size() > 0) {
			%>
			<form action="../CategoryDelete" method="POST" name='form1'>
			<table>
<tr>
<td>Check</td>
<td>Nazwa kategorii</td>
<td>Gier w kategorii</td>
</tr>

			<%
	for (Category cat : catlist) {
		String categoryName = cat.getCategory();
		int categoryId = cat.getCategory_id();
		%>
					
<tr>
<td>
<%out.println("<input type=\"radio\" name=\"check\" value=\"" +categoryId +"\"" );
%>
</td>
<td><% out.println(categoryName); %></td>

		<td><%=gcatm.countByCategory(sessionFactory, s, categoryId)%></td>
		</tr>


<%
		} %>
		<tr><td></td><td><input type="submit" class="mainBtn" value="Usuń kategorię" /></td></tr>
</table>
</form>
<%
		} else if (catlist.size() == 0) out.println("Nie ma zadnych kategorii");

		%>
		
		<br />
					<div class="page-header">
<h2 class="page-title">Dodaj kategorie</h2>
</div>
<br />

			<form action="../CategoryAdd" method="POST" name='form1'>
			<table>
		
		<tr>
		<td>
		Nazwa kategorii:
		</td>
		<td>
		<input type="text" id="categoryName" name="categoryName" />
		</td>
		</tr>
		<tr>
		<td>
		</td>
		<td>
		<input type="submit" class="mainBtn" value="Dodaj kategorie" />
		</td>
		</tr>
</table>
</form>
<%
		s.getTransaction().commit();
		%>
	

</div>